/**
*
*拷贝当前测算信息以及相关测算信息产品
*
**/

global class MeasureCalcWebService {

    WebService static String sumbitManagerApproval(String mid){
        //子公司经理 销售管理部项目经理 销售部产品经理(集团) 系统管理员
        Set<String> rights = new Set<String>{'子公司经理','销售管理部项目经理','销售部产品经理(集团)','系统管理员'};
        User u = [select Id,Profile.Name from User where Id=:UserInfo.getUserId() ];
        if(!rights.contains(u.Profile.Name)) return '没有权限';
        SavePoint sp = Database.setSavepoint();
        try {
            Measure_Calculate__c m = new Measure_Calculate__c(Id =mid,ManagerApprovalProcess__c = true);
            update m;

            return '提交加审成功!';
            
        }
        catch (Exception e) {
            Database.rollback(sp);
            return '提交加审失败:'+e.getMessage();
        }
        
        


    }
    /*
    // 测算信息拷贝按钮
    WebService static String copyMeasureCalculate(String mid) {
        String rtn = '';
        try {
            // 获取测算信息
            Schema.DescribeSObjectResult m = Measure_Calculate__c.sObjectType.getDescribe();
            System.debug(m+'==============================');
            Map<String, Schema.SObjectField> fieldMap = m.fields.getMap();
            System.debug(m+'==============================');
            String sql = 'select ';
            String fields = '';
            for ( String field : fieldMap.keySet() ) {
                if (fields.length() > 0) {
                    fields += ',';
                }
                fields += field;
            }
            sql += fields;
            sql += ' from Measure_Calculate__c where Id = \'' + mid + '\'';
            Measure_Calculate__c oldMc = Database.query(sql);
            System.debug(oldMc+'==============================');



            // 获取测算信息产品 
            m = Measure_Calculate_Product__c.sObjectType.getDescribe();
            fieldMap = m.fields.getMap();

            sql = 'select ';
            fields = '';
            for (String field : fieldMap.keySet()) {
                if (fields.length() > 0) {
                    fields += ', ';
                }
                fields += field;
            }
            sql += fields;
            sql += ' from Measure_Calculate_Product__c where Measure_Calculate__c = \'' + mid + '\'';
            List<Measure_Calculate_Product__c> oldMcpList = Database.query(sql);
            System.debug(oldMcpList+'==============================');

            // 拷贝测算信息
            Measure_Calculate__c newMc = oldMc.clone(false, true);
            newMc.Status__c = '草案中';
            // newQuote.Contract__c = null;
            // newQuote.IsAdjustQuote__c = false;
            // newQuote.AdjustTo__c = null;
            //newMc.Name = 'Copy:' + oldMc.Name;
            insert newMc;
            System.debug(newMc+'==============================');

            // 拷贝测算信息产品
            List<Measure_Calculate_Product__c> newMcpList = new List<Measure_Calculate_Product__c>();
            for (Measure_Calculate_Product__c oldMcp : oldMcpList) {
                Measure_Calculate_Product__c newMcp = oldMcp.clone(false, true);
                newMcp.Measure_Calculate__c = newMc.Id;
                newMcpList.add(newMcp);
            }
            insert newMcpList;
            System.debug(newMcpList+'==============================');

            return newMc.Id;
        } catch (Exception e) {
            return e.getMessage();
        }
    }
    */
}